//-------------------------------------------------------------------------------------------------------
//      Copyright (c) 2005-2009, Be Nanashi-San 
// 
//      Permission is hereby granted, free of charge, to any person obtaining a 
//      copy of this software and associated documentation files (the "Software"), 
//      to deal in the Software without restriction, including without limitation 
//      the rights to use, copy, modify, merge, publish, distribute, sublicense, 
//      and/or sell copies of the Software, and to permit persons to whom the 
//      Software is furnished to do so, subject to the following conditions: 
// 
//      The above copyright notice and this permission notice shall be included in 
//      all copies or substantial portions of the Software. 
// 
//      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
//      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
//      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
//      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
//      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
//      FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
//      DEALINGS IN THE SOFTWARE. 
// 
//      File Name:   	K2chTipTextView.cpp
//      Author:      	Be Nanashi-San@598 in "BeOS - Zeta R4" Thread 
//						(http://pc8.2ch.net/test/read.cgi/os/1120676818/598)
//		Description:	互換K2chTipTextView.
//						VIEW_LIMITERで表示するレス数を制限できる(待ち時間が我慢ならないようなら)
//						PostMessage()使いまくり。Zetaでは-D_ZETA_USING_DEPRECATED_API_が必要
//						DisplayThreadViewからとMStickerかも使われ、条件が多少違うので煩わしくなっている。
//-------------------------------------------------------------------------------------------------------
#include <Message.h>
#include <Messenger.h>
#include <Window.h>
#include "messages.h"
#include "K2chTipTextView.h"

////////////////////////////////////////////////////////////////////////////////
// K2chTipTextView
//
//
////////////////////////////////////////////////////////////////////////////////
K2chTipTextView::K2chTipTextView(const char *name, uint32 flags)
	: Base2chTextView(name, flags)
	,fMouseDown(0)
{
}
////////////////////////////////////////////////////////////////////////////////
// MouseDown
//
//
////////////////////////////////////////////////////////////////////////////////
void
K2chTipTextView::MouseDown(BPoint where)
{
	BTextView::MouseDown(where);
	fMouseDown = Window()->CurrentMessage()->FindInt32("clicks");
}
////////////////////////////////////////////////////////////////////////////////
// MouseUp
//
//
////////////////////////////////////////////////////////////////////////////////
void
K2chTipTextView::MouseUp(BPoint where)
{
	BTextView::MouseDown(where);

 	if (fMouseDown){
 	 /* MouseDownがなくMouseUpのみではPostしない
 		DeactiveなWindowへのClickはActiveにするだけでMouseDownを報告しない */
		/* Dragの終了 */
 		BMessenger(this->Window()).SendMessage(kMSG_MOUSE_UP);
	}
	
	fMouseDown = 0;
}
////////////////////////////////////////////////////////////////////////////////
// MouseMoved
//
//
////////////////////////////////////////////////////////////////////////////////
void
K2chTipTextView::MouseMoved(BPoint where, uint32 transit, const BMessage *msg)
{
	BTextView::MouseMoved(where, transit, msg);

	if (transit == B_INSIDE_VIEW) {
		BTextView::SetViewCursor(B_CURSOR_SYSTEM_DEFAULT);
		if (fMouseDown) {
 			BMessage msg(kMSG_MOUSE_DOWN_MOVE);
			msg.AddPoint("point", where /*- fMousePoint*/);
			BMessenger(this->Window()).SendMessage(&msg);
		}
	}else if (transit == B_EXITED_VIEW) {
	/* Window()はMStickerに対するものでmainWindowは単純に無視する */
 		fMouseDown = 0;
		BMessenger(this->Window()).SendMessage(kMSG_EXITED_VIEW);
	}else if (transit == B_ENTERED_VIEW) {
		fMouseDown = 0;
		BTextView::SetViewCursor(B_CURSOR_SYSTEM_DEFAULT);
	}
}
////////////////////////////////////////////////////////////////////////////////
// WindowActivated
//
//
////////////////////////////////////////////////////////////////////////////////
void
K2chTipTextView::WindowActivated(bool state)
{
	/* なくてもいいのだがまぁ見ためですから */
	if (! state) {
		BTextView::PushState();
		BTextView::SetHighColor(128, 128, 128, 128);
		BTextView::SetDrawingMode(B_OP_MAX);
		BTextView::FillRect(Bounds());
		BTextView::PopState();
	}
}
